package com.examonline.service.impl;

import com.examonline.pojo.Admin;
import com.examonline.pojo.Student;
import com.examonline.pojo.Teacher;
import com.examonline.pojo.dto.LoginDTO;
import com.examonline.pojo.vo.UserVO;
import com.examonline.service.AdminService;
import com.examonline.service.StudentService;
import com.examonline.service.TeacherService;
import com.examonline.service.UserService;
import com.examonline.utils.result.Result;
import com.examonline.utils.result.ResultEnum;
import com.examonline.utils.result.ResultUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class UserServiceImpl implements UserService {

    @Resource
    private AdminService adminService;
    @Resource
    private StudentService studentService;
    @Resource
    private TeacherService teacherService;

    @Override
    public Result login(LoginDTO loginDTO) {
        // 前端数据判断
        if(loginDTO==null){
            return ResultUtil.error(ResultEnum.USERNAME_PASSWORD_IS_NULL);
        }else {
            if(loginDTO.getTypeId()==0){
                return adminService.login(loginDTO);
            }else if(loginDTO.getTypeId()==1){
                return teacherService.login(loginDTO);
            }else if(loginDTO.getTypeId()==2){
                return studentService.login(loginDTO);
            }else {
                return ResultUtil.error(ResultEnum.TYPE_UNDEFINED);
            }
        }

    }
}
